/*
 * Copyright (c) 2017-2019, Lindenis Tech. Ltd.
 * All rights reserved.
 *
 * File:
 *
 * Description:
 *
 * Author:
 *      xiaoshujun@lindeni.com
 *
 * Create Date:
 *      2020/10/16
 *
 * History:
 *
 */

#ifndef __FF_CODEC_H__
#define __FF_CODEC_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "lindcomponent.h"

typedef struct _ffcodec_config_t
{
    av_enc_type_t aenc_type;
    int channels;
    int sample_rate;
    int bits;
    int period_size;
    int bitrate_audio;
    int attach_head;    // such as: ADTS

    av_enc_type_t venc_type;
    int width;
    int height;
    int framerate;

    uint8_t *extradata;
    int extradata_size;

    mppsource_callback_t cb;
} ffcodec_config_t;

_handle_t ff_aenc_create();
void ff_aenc_destroy(_handle_t h_codec);
int  ff_aenc_start(_handle_t h_codec, ffcodec_config_t * p_config);
int  ff_aenc_stop(_handle_t h_codec);
int  ff_aenc_send_data(_handle_t h_codec, av_frame_t * p_frame);
int  ff_aenc_receive_frame(_handle_t h_codec, av_frame_t * p_frame);

typedef struct _ffadec_config_t
{
    av_enc_type_t aenc_type;

    /*
     * user wanted PCM format
     * it set '0', any format is ok.
     */
    int channels;
    int sample_rate;
    int bits;

    /*
     * AVStream point from ffdemux
     * If this is set, 'aenc_type' is invalid.
     */
    void * p_priv;

    /*
     * For real-time communication low latency mode
     * use a small out frame cache.
     */
    int low_latency;
} ffadec_config_t;

_handle_t ff_adec_create();
void ff_adec_destroy(_handle_t h_codec);
int  ff_adec_start(_handle_t h_codec, ffadec_config_t * p_config);
int  ff_adec_stop(_handle_t h_codec);
void ff_adec_flush(_handle_t h_codec);
int  ff_adec_send_data2(_handle_t h_codec, av_frame2_t * p_frame);
int  ff_adec_receive_frame2(_handle_t h_codec, av_frame2_t ** p_frame);
int  ff_adec_return_frame2(_handle_t h_codec, av_frame2_t * p_frame);

#ifdef __cplusplus
}
#endif

#endif  // __FF_CODEC_H__


